﻿@using ZoomLa.Model
@model ZoomLaCMS.Models.Content.VM_ContentManage
@functions {

}
@{
    string adminPath = CustomerPageAction.customPath2;
}
@section head{<title>内容管理</title>}
@section content{
    <div id="BreadDiv" class="container-fluid mysite">
        <div class="row">
            <ol id="BreadNav" class="breadcrumb navbar-fixed-top">
                <li><a href="@(adminPath)Main.aspx">工作台</a></li>
                <li><a href="ContentManage">内容管理</a></li>
                <li class="active"><a href="ContentManage" title="@(Model.nodeMod.NodeName)">@(Model.nodeMod.NodeName)</a></li>
                <div class="pull-right hidden-xs">
                    <span>
                        <a href="@(adminPath)Content/SchedTask.aspx" title="查看计划任务">
                            <span class="fa fa-clock-o" style="color:#28b462;"></span>
                        </a>
                        @if (Model.NodeID > 0)
                        {
                            <a href="/Class_@Model.NodeID/Default.aspx" target="_blank" title="前台浏览">
                                <span class="fa fa-eye"></span>
                            </a>
                            <span onclick="opentitle('@(adminPath)content/Node/EditNode.aspx?NodeID=@(Model.NodeID)','配置本节点');" class="fa fa-cog" title="配置本节点" style="cursor:pointer;margin-left:5px;"></span>
                        }
                    </span>
                </div>
            </ol>
        </div>
    </div>
    <div class="opion_header">
        内容操作：@MvcHtmlString.Create(Model.GetAddHtml())
        @if (Model.nodeMod.NodeID > 0)
    {
            <span class="pull-right visible-xs visible-sm" id="m_span"><input type="button" class="btn btn-success m_modal" onclick="opentitle('@(adminPath)/Content/Node/EditNode.aspx?NodeID=@Model.NodeID',' 配置本节点')" value="节点选择" /></span>
        }
        <span class="pull-right hidden-xs count">
            文章数：@Model.Count_WZS
            点击数：@Model.Count_DJS
        </span>
    </div>
    <form id="imp_form" method="post" enctype="multipart/form-data" action="@MVCHelper.GetAction("ContentManage_Import",Request)" onsubmit="return ImportExcel();">
        <div id="divImp" class="Imp_div">
            选择CSV导入源：<input type="file" id="fileImp" name="fileImp" class="fileImp" accept=".xls,.xlsx,.csv" />
            <input type="submit" class="btn btn-default" id="upoffice_btn" value="导入" />
            @*<asp:Button ID="btnCurrentImport" CssClass="btn btn-default" runat="server" OnClick="btnCurrentImport_Click" OnClientClick="if(document.getElementById('fileImp').value.length==0){alert('请选择Excel(CSV)文件,可下载模板!');return false};" Text="导入"/>*@
            <span class="red">*</span> <a id="downimp" href=""><span id="downspan" class="Down"></span></a>(下载后用EXCEL打开从第二行开始按规范填写并保存即可)
            <input type="hidden" id="ModelID_H" name="ModelID" />
        </div>
    </form>
    <form method="post" id="form1">
        <ul class="nav nav-tabs hidden-xs hidden-sm">
            <li><a href="#tab" data-toggle="tab" onclick="ShowTabs('')">所有内容</a></li>
            @*<li><a href="#tab5" data-toggle="tab" onclick="ShowTabs(5)">工作流审批</a></li>*@
            <li><a href="#tab-3" data-toggle="tab" onclick="ShowTabs('@((int)ZLEnum.ConStatus.Draft)')">草稿</a></li>
            <li><a href="#tab0" data-toggle="tab" onclick="ShowTabs('@((int)ZLEnum.ConStatus.UnAudit)')">待审核</a></li>
            <li><a href="#tab99" data-toggle="tab" onclick="ShowTabs('@((int)ZLEnum.ConStatus.Audited)')">已审核</a></li>
            <li><a href="#tab-1" data-toggle="tab" onclick="ShowTabs('@((int)ZLEnum.ConStatus.Reject)')">退稿</a></li>
        </ul>
        <div id="condiv">
            @Html.Partial("ContentManage_List", Model)
        </div>
        <div class="clearfix"></div>
        <div>
            <input type="button" class="btn btn-info" value="删除" onclick="mvcpage.bat({ url: 'ContentManage_Del', confirm: '确定要移入回收站吗'});" />
            <input type="button" class="btn btn-info" value="定时发布" onclick="$('#timeReDiv').show();"/>
            <input type="button" class="btn btn-info" value="推荐" onclick="mvcpage.bat({ url: 'ContentManage_Elite', data: {elite:1}});" />
            <input type="button" class="btn btn-info" value="取消推荐" onclick="mvcpage.bat({ url: 'ContentManage_Elite', data: {elite:0} })" />
            <input type="button" class="btn btn-info" value="移动" onclick="batMove();" />
            <input type="button" class="btn btn-info" value="添加到专题" onclick="batSpecial();" />
            @*<input type="button" class="btn btn-info" value="批量修改" />*@
            <input type="button" class="btn btn-info" value="退稿" onclick="batStatus('@((int)ZLEnum.ConStatus.Reject)')" />
            <input type="button" class="btn btn-info" value="审核通过" onclick="batStatus('@((int)ZLEnum.ConStatus.Audited)');" />
            <input type="button" class="btn btn-info" value="取消审核" onclick="batStatus('@((int)ZLEnum.ConStatus.UnAudit)')" />
            <input type="button" class="btn btn-info" value="推送内容" onclick="batPush();" />
            <input type="button" class="btn btn-info" value="导出Excel" onclick="ToExcel();" />

            @*
                <input type="button" id="timeReBtn" value="<%=Resources.L.定时发布 %>" class="btn btn-info" onclick="$('#timeReDiv').show();" />
                <asp:Button ID="Button1"  runat="server"
                    Text="<%$Resources:L,批量修改 %>" CssClass="btn btn-info" OnClientClick="if(!IsSelectedId()){alert('请选择修改项');return false;}else{return confirm('你确定要修改选中内容吗？')}"
                    OnClick="Button1_Click" />
                <asp:Button ID="ExportExcel_B" runat="server" Text="导出Excel" CssClass="btn btn-info" OnClick="ExportExcel_B_Click" />*@
        </div>
        @*<div visible="false" runat="server" id="audit_Div" class="margin_t10">
                <asp:Button runat="server" CssClass="btn btn-success" ID="NextStep_Btn" OnClick="NextStep_Btn_Click" Text="<%$Resources:L,工作流批量审批 %>" OnClientClick="return confirm('确定要批量审批吗!');" />
                <asp:Button runat="server" CssClass="btn btn-success" ID="StepReject_Btn" OnClick="StepReject_Btn_Click" Text="<%$Resources:L,工作流批量拒绝 %>" OnClientClick="return confirm('确定要批量拒绝吗!');" />
            </div>*@
        <div id="timeReDiv" style="display:none;" class="margin_t10">
                <table class="table table-bordered">
                    <tr>
                        <td class="td_m"><strong>执行时间：</strong></td>
                        <td><input type="text" id="timeReBTime" class="form-control text_300 margin-l5" name="timeReBTime" onclick="WdatePicker({ dateFmt: 'yyyy/MM/dd HH:mm:ss' });" /></td>
                    </tr>
                    <tr>
                        <td><strong>操作：</strong></td>
                        <td>
                            <button type="button" id="timeReConfBtn" class="btn btn-group" onclick="if (scheCheck()) { mvcpage.post({ url: 'ContentManage_TimeRelease', data: { ids: mvcpage.help.getchk('idchk'), retime: $('#timeReBTime').val() }, callback: 'timere_cback' }); };" >创建任务</button>
                            <input type="button" value="取消" onclick="closeDiv()" class="btn btn-group" />
                        </td>
                    </tr>
                </table>
            </div>
        <input type="hidden" class="mvcparam" data-type="json" value="@(Model.filter.ToJson())" />
    </form>
    <div style="height:20px;"></div>
}
@section script{
<script src="/JS/SelectCheckBox.js"></script>
<script src="/JS/DatePicker/WdatePicker.js"></script>
<script src="/JS/Controls/ZL_Dialog.js"></script>
<script src="/JS/ZL_Regex.js"></script>
<script>
        function closeDiv() { $("#timeReDiv").css("display", "none"); }
        function scheCheck() {
            var time = Date.parse($("#timeReBTime").val());
            var now = new Date();
            if (time < now) { alert("执行时间无效"); return false; }
            var len = $("input[name=idchk]:checked").length;
            if (len < 1) { alert("未选择文章"); return false; }
            return true;
        }
        function timere_cback(data,result) {
            if (result == 1) { alert('添加成功'); }
            else { alert(result); }
        }
        $(function () {
            $("#chkAll").click(function () {
                selectAllByName(this, "idchk");
            });
            if ("@Request["status"]") {
                $("li a[href='#tab@(Request["status"])']").parent().addClass("active");
            } else { $("li a[href='#tab']").parent().addClass("active"); }
            $(".precode").hover(function () {
                $(this).closest("td").find(".popover").show();
            }, function () {
                $(this).closest("td").find(".popover").hide();
            });
        });
        function MoveItem(obj, direct) {
            var $curtr = $(obj).closest("tr");
            var $tarTr = null;
            switch (direct) {
                case "up":
                    $tarTr = $curtr.prev("tr");
                    if ($tarTr.length < 1 || $tarTr.data("gid") == undefined) { console.log("无目标行,不处理"); return; }
                    $curtr.after($tarTr);
                    break;
                case "down":
                    $tarTr = $curtr.next("tr");
                    if ($tarTr.length < 1 || $tarTr.data("gid") == undefined) { console.log("无目标行,不处理"); return; }
                    $tarTr.after($curtr);
                    break;
            }
            var opts = { action: "move", "direct": direct, curid: $curtr.data("gid"), tarid: $tarTr.data("gid") };
            $.post("ContentManage_API", opts, function (data) { });
        }
        function ShowDesk() {
            var ifr = $("#page_ifr")[0];
            window.location = ifr.contentWindow.location;
        }
        function ShowTabs(status) {
            location.href = 'ContentManage?NodeID=@Model.NodeID&status=' + status;
        }
        function opentitle(url, title) {
            diag.title = title;
            diag.url = url;
            diag.reload = true;
            diag.ShowModal();
        }

        var diag = new ZL_Dialog();
        function ShowPopover(obj) {
            $(obj).find(".popover").show();
        }
        function HidePopover(obj) {
            $(obj).find(".popover").hide();
        }
        document.onkeyup = function GetKeyCode() {
            if (event.keyCode == 46) {
                $("#btnDeleteAll").trigger("click");
            }
        }
        function IsSelectedId() {
            var checkArr = $("input[type=checkbox][name=idchk]:checked");
            if (checkArr.length > 0)
                return true
            else
                return false;
        }
        function ImportExcel() {
            if ($("#fileImp").val() == "") { alert("请先下载模板,再上传数据文件导入"); return false; }
            return true;
        }
        function showimp(itemname, modelid) {
            $("#ModelID_H").val(modelid);
            $("#downimp").attr("href", "Import_ToTemplate?ModelID=" + modelid);
            $("#downspan").html("下载[@Model.nodeMod.NodeName]的" + itemname + "模型CSV导入模板");
            $("#divImp").show();
        }
        //-----页面功能
        function batMove() {
            var ids = mvcpage.help.getchk("idchk");
            if (checkIDS()) { location = "@(adminPath)Content/ContentMove.aspx?id=" + ids; }
        }
        function batSpecial() {
            var ids = mvcpage.help.getchk("idchk");
            if (checkIDS()) { location = "@(adminPath)Content/AddToSpecial.aspx?id=" + ids; }
        }
        function batPush() {
            if (checkIDS()) { ShowSelNode(); }

        }
        function batStatus(status) {
            if (checkIDS()) {
                mvcpage.bat({ url: 'ContentManage_Status', data: { "status": status } });
            }
        }
        function checkIDS() {
            var ids = mvcpage.help.getchk("idchk");
            if (ZL_Regex.isEmpty(ids)) { alert("未选中内容"); return false; }
            else { return true; }
        }
        function ToExcel() {
            var $form = $('<form method="post" action="ContentManage_ToExcel" target="_blank" id="form2">');
            var filter = mvcpage.help.getPageFilter({ target: "EGV" });
            for (var key in filter) {
                $form.append('<input type="hidden" name="' + key + '" value="' + filter[key] + '" />');
            }
            $("body").append($form);//兼容 IE
            $("#form2").submit();
            $("#form2").remove();
        }
        //-----内容推送
        function ShowSelNode() {
            comdiag.maxbtn = false;
            ShowComDiag("/Common/NodeList.aspx?Source=content", "请选择需推送的节点<input type='button' value='确定推送' onclick='SurePush();' class='btn btn-primary'>");
        }
        function SurePush() {
            var content = comdiag.iframe.contentWindow;
            content.SureFunc();
        }
        //pushcon,要推送的节点列表,页面pval
        function PageCallBack(action, vals, pval) {
            var nids = "", ids = "";
            for (var i = 0; i < vals.length; i++) {
                nids += vals[i].nodeid + ",";
            }
            $("input[name='idchk']:checked").each(function () {
                ids += this.value + ",";
            });
            ids = StrHelper.trim(ids);
            nids = StrHelper.trim(nids);
            if (ZL_Regex.isEmpty(nids)) { alert("未选择需要推送的节点"); return false; }
            else {
                var mask = new ZL_Dialog();
                mask.ShowMask("正在推送文章中");
                $.post("Content_Push", { "ids": ids, "nodes": nids }, function (data) {
                    if (data == "1") { mask.CloseModal(); comdiag.CloseModal(); }
                    else { alert(data); }
                });
            }
        }
    </script>
}